export default {
  setTitle (title) {
    document.title = title
    if (/ip(hone|od|ad)/i.test(navigator.userAgent)) {
      var i = document.createElement('iframe')
      i.src = '/favicon.ico'
      i.style.display = 'none'
      i.addEventListener('load', function () {
        setTimeout(function () {
          i.removeEventListener('load')
          document.body.removeChild(i)
        }, 4)
      }, false)
      document.body.appendChild(i)
    }
  },

  getUrlParam (name, url) {
    url = url == null ? window.location.href : url
    url = url.split('#')[0]

    var reg = new RegExp('(^|\\?|&)' + name + '=([^&]*)(\\s|&|$)', 'i')
    return reg.test(url) ? RegExp.$2.replace(/\+/g, ' ').replace('null', '') : ''
  },

  go (url, $router) {
    if (!url) return
    const useRouter = typeof url === 'object' || ($router && typeof url === 'string' && !/http/.test(url))
    if (useRouter) {
      $router.push(url)
    } else {
      window.location.href = url
    }
  }


  // hex 转 hsl 转rgb
  // http://www.zhangxinxu.com/wordpress/2010/03/javascript-hex-rgb-hsl-color-convert/
  // http://www.imooc.com/article/2523

  // getUrlParam (name, url) {
  //     url = url == null ? window.location.href : url
  //     url = url.split('#')[0]
  //
  //     var reg = new RegExp('(^|\\?|&)' + name + '=([^&]*)(\\s|&|$)', 'i')
  //     return reg.test(url) ? RegExp.$2.replace(/\+/g, ' ').replace('null', '') : ''
  // },
  // toUrlParam(obj){
  //   var str=[]
  //   for(var i in obj){ str.push(i+'='+obj[i]) }
  //   return str.join('&')
  // },
  // addBaiduTongji: function() {
  //     var _hmt = _hmt || [];
  //     var isProduct = this.isProduct();
  //     var hm = document.createElement("script");
  //     hm.src = "//hm.baidu.com/hm.js?eb461dc211b77935a84dde750341f0ed"
  //     var s = document.getElementsByTagName("script")[0]
  //     s.parentNode.insertBefore(hm, s)
  // },
  //
  // isWechat: function() {
  //     return navigator.userAgent.match(/MicroMessenger\/([\d\.]+)/i)
  // },

}

// location.port 如果没有端口号就添加百度统计
